package com.sxhuayuan.parking.socket;

import org.apache.commons.codec.digest.DigestUtils;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class AuthorizationToken {

	private String user;
	private Long timestamp;
	private String sign;

	public void sign(String key) {
		this.sign = DigestUtils.md5Hex(String.format("timestamp=%s&user=%s&key=%s", timestamp, user, key));
	}

	public boolean isSignValid(String key) {
		String str = String.format("timestamp=%s&user=%s&key=%s", timestamp, user, key);
		String sign2 = DigestUtils.md5Hex(str);
		return sign2.equalsIgnoreCase(this.sign);
	}
}
